var t = require("../../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Component({
    properties: {
        advertisingt_id: {
            value: 10,
            type: Number
        },
        commentsShow: {
            value: !1,
            type: Boolean
        },
        autoRequest: {
            value: !1,
            type: Boolean
        }
    },
    data: {
        mainCommentShow: !1,
        maincomment: "",
        comment_total: 0,
        comment_page: 1,
        comment_loading: !1,
        comment_total_count: 0,
        StickCommentData: [],
        replyName: "",
        replyContent: "",
        host_comment_id: "",
        second_comment_id: "",
        is_own: !1,
        commentManagement: !1,
        replyshow: !1
    },
    ready: function() {
        this.data.autoRequest && this.getStickComment();
    },
    methods: {
        subMainCommentBtn: function() {
            this.setData({
                maincomment: "",
                mainCommentShow: !this.data.mainCommentShow
            });
        },
        openComments: function() {
            this.setData({
                commentsShow: !this.data.commentsShow
            }), this.triggerEvent("closeComment");
        },
        subMainBtn: function() {
            if (!this.data.maincomment) return e.tips("请输入你的精彩评论");
            this.setData({
                mainCommentShow: !1
            }), this.getReplyComments("main");
        },
        getReplyComments: function(t) {
            var a = this, n = {}, i = e.getNetAddresss("plugin.new-media-advertising.frontend.comment.comment");
            n.advertisingt_id = this.data.advertisingt_id, n.comment = "main" == t ? this.data.maincomment : this.data.replyContent, 
            "reply" == t && (this.data.host_comment_id && (n.parent_id = this.data.host_comment_id), 
            this.data.second_comment_id && (n.subordinate_id = this.data.second_comment_id)), 
            e._postNetWork({
                url: i,
                showToastIn: !1,
                data: n,
                success: function(t) {
                    var n = t.data;
                    e.tips(n.msg), 1 == n.result && (a.getStickComment(), a.triggerEvent("commentSuccess", {
                        type: "add"
                    }), n.data.is_reward && 1 == n.data.is_reward && a.triggerEvent("reward", n.data));
                },
                fail: function(t) {}
            });
        },
        getStickComment: function() {
            var t = this;
            this.setData({
                comment_page: 1,
                comment_total: 0
            });
            var a = {
                advertisingt_id: this.data.advertisingt_id
            }, n = e.getNetAddresss("plugin.new-media-advertising.frontend.comment.get-comment-list");
            e._postNetWork({
                url: n,
                showToastIn: !1,
                data: a,
                success: function(a) {
                    var n = a.data;
                    1 == n.result ? t.setData({
                        comment_total: n.data.last_page,
                        StickCommentData: n.data.data,
                        comment_total_count: n.data.total
                    }) : e.tips(n.msg);
                },
                fail: function(t) {}
            });
        },
        replyCommentsBtn: function(t) {
            var e = t.currentTarget.dataset.hostcommentid, a = t.currentTarget.dataset.secondcommentid, n = t.currentTarget.dataset.uname, i = t.currentTarget.dataset.content, m = t.currentTarget.dataset.isown;
            this.setData({
                host_comment_id: e,
                second_comment_id: a,
                replyContent: "",
                replyName: n,
                replyshowcontent: i
            }), 1 == m ? this.setData({
                is_own: !0
            }) : this.setData({
                is_own: !1
            }), this.setData({
                commentManagement: !0
            });
        },
        replyBtn: function() {
            this.setData({
                replyshow: !0,
                commentManagement: !1
            });
        },
        replySubmitBtn: function() {
            if (!this.data.replyContent) return e.tips("请输入回复内容");
            this.setData({
                replyshow: !1
            }), this.getReplyComments("reply");
        },
        replyshowClose: function() {
            this.setData({
                replyshow: !1
            });
        },
        commentManagementClose: function() {
            this.setData({
                commentManagement: !1
            });
        },
        delBtn: function() {
            this.data.host_comment_id && this.data.second_comment_id ? this.setData({
                commend_id: this.data.second_comment_id
            }) : this.setData({
                commend_id: this.data.host_comment_id
            }), this.setData({
                commentManagement: !1
            }), this.delReply();
        },
        delReply: function() {
            var t = this, a = {}, n = e.getNetAddresss("plugin.new-media-advertising.frontend.comment.delete-comment");
            a.comment_id = this.data.commend_id, e._postNetWork({
                url: n,
                showToastIn: !1,
                data: a,
                success: function(a) {
                    var n = a.data;
                    e.tips(n.msg), 1 == n.result && (t.triggerEvent("commentSuccess", {
                        type: "reduce"
                    }), t.getStickComment());
                },
                fail: function(t) {}
            });
        },
        praiseBtn: function(t) {
            var a = t.currentTarget.dataset.hostcommentid, n = t.currentTarget.dataset.secondcommentid, i = t.currentTarget.dataset.index, m = t.currentTarget.dataset.chilindex;
            if (1 == t.currentTarget.dataset.ispraise) return e.tips("你已赞过该贴");
            this.getPraiseData(a, n, i, m);
        },
        getPraiseData: function(a, n, i, m) {
            var s = this, o = {}, c = e.getNetAddresss("plugin.new-media-advertising.frontend.comment.comment-like");
            o.advertisingt_id = this.data.advertisingt_id, o.comment_id = a && n ? n : a, e._postNetWork({
                url: c,
                showToastIn: !1,
                data: o,
                success: function(o) {
                    var c, d, r = o.data;
                    (e.tips(r.msg), 1 == r.result) && (a && n ? s.setData((t(c = {}, "StickCommentData.[" + i + "].has_many_comment[" + m + "].is_like", 1), 
                    t(c, "StickCommentData.[" + i + "].has_many_comment[" + m + "].like_count", s.data.StickCommentData[i].has_many_comment[m].like_count ? s.data.StickCommentData[i].has_many_comment[m].like_count + 1 : 1), 
                    c)) : s.setData((t(d = {}, "StickCommentData[" + i + "].is_like", 1), t(d, "StickCommentData[" + i + "].like_count", s.data.StickCommentData[i].like_count ? s.data.StickCommentData[i].like_count + 1 : 1), 
                    d)));
                },
                fail: function(t) {}
            });
        },
        getMoreStickComment: function() {
            var t = this, a = {
                advertisingt_id: this.data.advertisingt_id
            };
            if (!this.data.comment_loading) {
                this.setData({
                    comment_loading: !0
                });
                var n = e.getNetAddresss("plugin.new-media-advertising.frontend.comment.get-comment-list");
                this.data.comment_page >= this.data.comment_total ? this.setData({
                    loading: !0
                }) : (this.setData({
                    comment_page: this.data.comment_page + 1
                }), a.page = this.data.comment_page, e._postNetWork({
                    url: n,
                    showToastIn: !1,
                    data: a,
                    success: function(e) {
                        var a = e.data;
                        if (1 == a.result) {
                            var n = a.data.data;
                            t.setData({
                                StickCommentData: t.data.StickCommentData.concat(n),
                                comment_loading: !1
                            });
                        } else t.setData({
                            comment_page: t.data.comment_page - 1,
                            comment_loading: !1
                        });
                    },
                    fail: function(t) {}
                }));
            }
        }
    }
});